<!DOCTYPE html>
<!--
  ~ Copyright (c)  2017, Zhao Jinbing.
  ~ Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  -->

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>JH_SSM | 登录</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="#(baseUrl)/assets/lib/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="#(baseUrl)/assets/lib/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="#(baseUrl)/assets/lib/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="#(baseUrl)/assets/lib/adminLTE/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="#(baseUrl)/assets/lib/iCheck/square/blue.css">

    <!-- web Font -->
    <link rel="stylesheet" href="https://fonts.lug.ustc.edu.cn/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <a href="../../index2.html"><b>JiaHui</b>SSM</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">Sign in to start your session</p>

        <form id="loginForm">
            <div class="form-group has-feedback">
                <input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名" required minlength="5" maxlength="20">
                <span class="glyphicon glyphicon-user form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" name="password" class="form-control" placeholder="请输入密码" required minlength="5" maxlength="20">
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label>
                            <input id="rememberMe" type="checkbox"> 记住我
                        </label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
                </div>
                <!-- /.col -->
            </div>
        </form>

    </div>
    <!-- /.login-box-body -->
</div>
<!-- jQuery 3 -->
<script src="#(baseUrl)/assets/lib/jquery/jquery.min.js"></script>
<!-- jquery.validate -->
<script src="#(baseUrl)/assets/lib/jquery-validation/jquery.validate.js"></script>
<script src="#(baseUrl)/assets/lib/jquery-validation/messages_zh.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="#(baseUrl)/assets/lib/bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="#(baseUrl)/assets/lib/iCheck/icheck.min.js"></script>
<!-- layer(弹层) -->
<script src="#(baseUrl)/assets/lib/layer/layer.js"></script>
<script>
    $(function () {
        $('#rememberMe').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '15%' // optional
        });

        $('#loginForm').validate({
            errorElement: 'span',
            errorClass: 'help-block',
            highlight : function(element) {
                $(element).closest('.form-group').addClass('has-error');
            },
            success : function(label) {
                label.closest('.form-group').removeClass('has-error');
                label.closest('.form-group').addClass('has-success');
                label.remove();
            }
        });

        $('#loginForm').submit(function () {
            if (!$(this).valid()) {
                return false;
            }
            $.ajax({
                url: './login',
                data: $('#loginForm').serialize(),
                type: 'POST',
                dataType: 'JSON',
                success: function (res) {
                    if (res.success) {
                        window.location.href = './';
                    } else {
                        layer.msg(res.message, {time: 2000});
                    }
                }
            });
            console.log(1);
            return false;
        });

    });
</script>
</body>
</html>